use serde::Serialize;
use sqlx::FromRow;
use crate::base::ServerError;
use crate::db::get_conn;

#[derive(Debug, FromRow, Serialize)]
pub struct Group {
    pub id: i32,
    pub name: String,
    pub enable: bool,
}

pub async fn list_group() -> Result<Vec<Group>, ServerError> {
    let result = sqlx::query_as::<_, Group>(r#"
    select * from tb_group
    "#)
        .fetch_all(&get_conn())
        .await?;
    Ok(result)
}